home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8678 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  4.2 KB

  1. Path: mail2news.demon.co.uk!fatphil.demon.co.uk
  2. From: Phil Carmody <Phil@fatphil.demon.co.uk>
  3. Newsgroups: comp.lang.c++,comp.os.msdos.programmer
  4. Subject: Re: Timer (0x1C) Interrupt exactly 18.2 seconds?
  5. Date: Sun, 25 Feb 1996 21:07:26 GMT
  6. Organization: None
  7. Message-ID: <448372328wnr@fatphil.demon.co.uk>
  8. References: <4givrv$cim@midland.co.nz> <Dn9FMB.19s.0.sheppard@torfree.net>
  9. Reply-To: Phil@fatphil.demon.co.uk
  10. X-NNTP-Posting-Host: fatphil.demon.co.uk
  11. X-Broken-Date: Sunday, Feb 25, 1996 21.07.26
  12. X-Newsreader: Newswin Alpha 0.7
  13. X-Mail2News-Path: fatphil.demon.co.uk
  14.  
  15. In article: <Dn9FMB.19s.0.sheppard@torfree.net>  ak892@torfree.net (Bruce DeVisser) writes:
  16. > Jarrod S Lowe (lowefam@igrin.co.nz) wrote:
  17. > : Hi
  18. > : I have a C++ Program (on DOS) in which a function is attached to the
  19. > : Timer (0x1C) Interrupt.
  20. > : [snip]
  21. > : This program is expected to run, continually, for YEARS - so a drift
  22. > : that shows up in 5 minutes will make it unusable.
  23. > : Does anybody have any ideas WHY this is happening?
  24. > Yes; because the timer is not exactly 18.2 Hz. Try taking the oscillator 
  25. > frequency -- 1.19318 MHz (which may drift slightly, so don't get too 
  26. > carried away with precision), dividing it by 65536, and see what you come 
  27. > up with.
  28. >    Bruce DeVisser
  29.  
  30. This comes from the asm.x86 group, where we've just had a similar 
  31. discussion
  32.  
  33.  
  34. In article: <3124955A.2EF1@hda.hydro.com>  Terje Mathisen 
  35. <Terje.Mathisen@hda.hydro.com> writes:
  36. > Here's another way to translate the 18.206...Hz ticks into 
  37. > seconds: Multiply the ticks by the ratio 1913/34829 = 
  38. > 18.20648196.
  39. > This is the closest possible 16-bit only rational approximation 
  40. > to the true value, it is probably more accurate than the clock 
  41. > frequency of most PCs, so there's no need to try to improve upon 
  42. > it.
  43.  
  44. Sorry Terje, 
  45. I beg to differ in the 8th significant digit!! I think you're hoisted 
  46. with your own petard (in the shape of the 'probably' disclaimer).
  47.  
  48. You assume Clock Frequency = 1193180 Hz
  49.  
  50. I assume the following -
  51. NTSC clocks at 14318180Hz (look at the clock chips on your MB and VGA)
  52. Timer = NTSC/12 = 1193181.7 Hz
  53.  
  54. We bath/all know that the DOS timer (typically) = Timer/65536
  55.  
  56. For low/medium accuracy, we agree...
  57.  
  58. approximate   18.206507364909 (my value)
  59.    18/1     = 18.000000000000 = 2.065074e-01 out (1st continued fraction)
  60.    55/3     = 18.333333333333 = 1.268260e-01 out
  61.    73/4     = 18.250000000000 = 4.349264e-02 out
  62.    91/5     = 18.200000000000 = 6.507365e-03 out (2nd continued fraction)
  63.   346/19    = 18.210526315789 = 4.018951e-03 out
  64.   437/24    = 18.208333333333 = 1.825968e-03 out
  65.   528/29    = 18.206896551724 = 3.891868e-04 out (4th continued fraction)
  66.  1147/63    = 18.206349206349 = 1.581586e-04 out
  67.  1675/92    = 18.206521739130 = 1.437422e-05 out
  68.  
  69.  
  70. For high accuracy, we diverge
  71.  
  72. approximate   18.206507364909 (my value)
  73.  7847/431   = 18.206496519722 = 1.084519e-05 out
  74.  9522/523   = 18.206500956023 = 6.408886e-06 out
  75. 11197/615   = 18.206504065041 = 3.299868e-06 out
  76. 12872/707   = 18.206506364922 = 9.999866e-07 out
  77. 14547/799   = 18.206508135169 = 7.702601e-07 out
  78. 27419/1506  = 18.206507304117 = 6.079199e-08 out
  79.  
  80. approximate   18.206481933594 (your value)
  81.  2822/155   = 18.206451612903 = 3.032069e-05 out
  82.  4497/247   = 18.206477732794 = 4.200800e-06 out
  83. 10669/586   = 18.206484641638 = 2.708044e-06 out
  84. 15166/833   = 18.206482593037 = 6.594435e-07 out
  85. 19663/1080  = 18.206481481481 = 4.521123e-07 out
  86. 34829/1913  = 18.206481965499 = 3.190546e-08 out
  87.  
  88. So if you are going to pull some 'magic numbers' out of the bag, don't
  89. bother using either mine or Terje's, only used the shared values until
  90. some more evidence is found.
  91.  
  92. If I'm right about the frequency, then 1675/92 is more accurate than 
  93. any of your ratios would be, and vica versa. If we are both wrong, then
  94. probably both set of magic values will be rubbish!
  95.  
  96. I use 528/29 and am happy with the 15 bits it gives me.
  97.  
  98.  
  99. Phil
  100.  
  101.  
  102. I then posted another, but have lost that - here's the gist
  103.  
  104. the crystals on a pc typically are 100ppm. That's roughly 
  105. 8.6 seconds per day, or 1.82e-03s per clock tick.
  106.  
  107.  
  108. So it looks like it's bad news on the accuracy front...
  109. Phil
  110. -- 
  111. Phil Carmody
  112. The views expressed herein are mine, so no ripping them off OK!
  113.  
  114.  
  115.  
  116.  
  117.  
  118. -- 
  119. Phil Carmody
  120. The views expressed herein are mine, so no ripping them off OK!
  121.  
  122.